<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
	<head>
		<jsp:include page="../inc.jsp"></jsp:include>
		<jsp:include page="../head.jsp"></jsp:include>
		<meta http-equiv="X-UA-Compatible" content="edge" />
		<title>订单管理-合同订单管理</title>
		<style type="text/css">
		 .blue_btn{
			border: none;
			border-radius: 5px;
			background-color: #3989c8;
			padding: 5px 20px;
			color:#fff;
        }
        .mynewBtn{
		display: block;
		width:60px;
		height:20px;
		background: #3989c8;
		margin-left:18px;
		margin-top:3px;
		float: left;
		color: #FFFFFF;
		border:1px solid #3989c8;
		-moz-border-radius: 3px;      /* Gecko browsers */
	    -webkit-border-radius: 3px;   /* Webkit browsers */
	    border-radius:3px;
	    cursor:pointer;
	}
        .beizhu{
        	color:#fff;
        	border-radius: 5px;
            background-color: #3989c8;
        	width:80px;
        	padding:5px 10px;
        	font-size:14px;
        	text-align:center;
        	margin-top:5px;
        	
        }
        .beizhu:hover{
        cursor: pointer;
        }
        #toolbar{
           	height:70px;
          	width:100%;
            margin-top: 5px;
            overflow:hidden;
        }
        .list{
            clear: both;
            width: 100%;
            list-style: none;
            padding-left:0px;
        }
        .list li{
            float: left;
            margin-right: 10px;
        }
        .textbox{
            height: 20px;
            margin: 0;
            padding: 0 2px;
            box-sizing: content-box;
            border: 1px solid #95B8E7;
            vertical-align: middle;
			border-radius:3px;
        }
        #tb{
       	padding-left:10px;
      
        }
   		#tb table{
   			border:1px solid #dbdbdb;
   			border-collapse:collapse;
   		}
   		#tb table thead th{
   		border:1px solid #dbdbdb;
   			text-align:center;
   			width:100px;
   			font-size:12px;
   			color:#95B8E7;
   			height:25px;
   		}
   		#tb table td{
   			border:1px solid #dbdbdb;
   			text-align:center;
   			width:100px;
   			font-size:12px;
   			
   		}
   		a{
			text-decoration: none;
			color: #7c7e7d;
		}
   		.combo{
   		border-radius:3px;
   		}
   		#tt .tabs li:first-child a{
   			padding-left:30px;
   			padding-right:30px;
   		}
   		.pew{
   			color:#ff0101;
   			font-size:14px;
   		}
   		.autoBoxTwo{
			width:180px;
			height:26px;
			margin:15px auto; 
		}
		</style>
		<script type="text/javascript">
		var msgTime;
		var msgStatus;
		//消息提醒
		function getInformation(){
			$.ajax({
				type:"post",
				url:"${ctx}/msg/message",
				success:function(data){
					console.log(data);
					for(var i=0;i<data.obj.length;i++){
						var prefix=data.obj[i];
							if(prefix.type == 5){
								msgTime = prefix.startTime;
								msgStatus = prefix.status;
						}
					}
					getInfoCount();
				},
				error:function(msg){
					layer.alert("请检查您的网络连接，然后重试！");
				}
			});
		};
		function getInfoCount(){
			$.ajax({
				type:"get",
				url:"${ctx}/nporder/selectStatus?lastLoginTime="+msgTime,
				success:function(data){
					$("#auditCount").html("("+data+")");
				},
				error:function(msg){
					layer.alert("请检查您的网络连接，然后重试！");
				}
			});
		};
		
		//封装函数实现到计时的效果
		function timeOut(checkTime){
			var date = checkTime.replace(/-/g,'/').replace("="," ");
			var timestamp = parseInt(new Date(date).getTime());// 获得支付截止时间的毫秒数 
			var timestamp_now = parseInt(new Date().getTime()); 
			var timestamp_gap=(timestamp-timestamp_now)/1000; //获取毫秒差转化为秒
			
			var payOvertime="";
			if(timestamp_gap>0){
				var h=Math.floor((timestamp_gap/3600)%24);
				var m=Math.floor((timestamp_gap/60)%60);
				var s=Math.floor(timestamp_gap%60);
				//console.log(h + ":" + m + ":" + s)
				 payOvertime=h + ":" + m + ":" + s;
			    return payOvertime;
			}else{
				payOvertime="时间到";
				return payOvertime;
			} 
		}
		$(function(){
			getInformation();
			$('#tt').tabs({ 
				width: $("#tt").parent().width()-20, 
				height:$("#tt").parent().height()-30
			});
			//加载表格信息
			dataGrid = $('#ticketTable').datagrid({
				url:'${ctx}/nporder/contractListForPlat?temp='+Math.random(),
				striped : true,
				singleSelect : true,
				idField : 'id',
				pageList : [5,10,20,40,60],
				method : 'get',
				pagination:true,
				columns:[[
				          {
								width : '80',
								title : 'id',
								field : 'id',
								hidden : true,
							},{
					width : '180',
					title : '合同号',
					align : 'center',
					field : 'conNo'
				},{
					width : '180',
					title : '外部合同号',
					align : 'center',
					field : 'pssConNo'
				},{
					width : '150',
					title : '出发',
					align : 'center',
					field : 'charterTypeStr',
					formatter : function(value,row){
						var str=row.deptAirport+'('+row.deptAirportCode+')';
						return str;
					}
				},{
					width : '150',
					title : '到达',
					align : 'center',
					field : 'scheduleId',
					formatter : function(value,row){
						var str=row.arrAirport+'('+row.arrAirportCode+')';
						return str;
					}
				},{
					width : '120',
					title : '产品列表',
					align : 'center',
					field : 'productList',
					formatter : function(value,row){
					//	var str='<span>'+row.toStartDate+'</span>'+'<br/>'+'<span>'+row.backStartDate+'</span>';
					//	return str;
						return CommonConverter.toEmptyString(row.productList);
					}
				},{
					width : '120',
					title : '押金金额(CNY)',
					align:'center',
					field : 'journeyType',
					formatter : function(value,row){
						var str="";
						if(row.deposit!=row.oldDeposit){
							str='<span class="pew">'+row.deposit+'</span>'+'<br/>'+'<s>'+row.oldDeposit+'</s>';
						}else{
							str='<span class="pew">'+row.deposit+'</span>';
						}
						return str;
						//var str='<span class="pew">'+row.deposit+'</span>'+'<br/>'+'<s>'+row.oldDeposit+'</s>';
						//return str;
					}
				},{
					width : '220',
					title : '状态',
					align:'center',
					field : 'orderStatus',
					formatter:function(value,row){
						var str=CommonConverter.toContractStatusStr(row.conStatus);
						if(row.conStatus==2){
							var timeId = "time"+row.conNo;
							var time = row.seconds;
							if(time>0){
								 var timer_rt = window.setInterval("GetRTime("+time+",'"+timeId+"')", 1000);
							}
							 str='<span style="color:#ff8800;">'+CommonConverter.toContractStatusStr(row.conStatus)+'</span><img src="${ctx}/image/delay_out.png" style="vertical-align:middle">'+
							'<br/>剩余保留时间：<span id="'+timeId+'"></span>';
						}
						return str;
					}
				},{
					width : '100',
					title : '买/卖家信息',
					align:'center',
					field : 'sellingPrice',
					formatter:function(value,row){
						var str='<span>卖：'+CommonConverter.toEmptyString(row.supName)+'</span>'+'<br/>'+'<span>买：'+CommonConverter.toEmptyString(row.custName)+'</span>'+'<br/>'+
						  '<span>真实姓名：'+CommonConverter.toEmptyString(row.contact)+'</span>'+'<br/>'+'<span>联系电话：'+CommonConverter.toEmptyString(row.mobile)+'</span>';
						return str;
					}
				},{
					width : '250',
					title : '操作',
					align:'center',
					field : 'fareSaleStr',
					formatter:function(value,row){
						var paymentTime=CommonConverter.toEmptyString(row.paymentOverTime);
						console.log(paymentTime);
						var str = '<div class="autoBoxTwo"><span class="mynewBtn" onclick=LookDetail("'+row.conNo+'","'+row.conStatus+'","'+paymentTime.replace(" ","=")+'")>查看详情</span>'+'<span class="mynewBtn" onclick=CheckLog("'+row.conNo+'")>查看日志</span></div>';
						return str;
					}
				}
				] ]
			});
			
			//点击查询 重新加载列表
			$("#query").click(function(){
				//出发到达城市清空处理
				alsoempty($("#homecity_name"),$("#_startCity"));
				alsoempty($("#getcity_name"),$("#_endCity"));
				//获取参数
				var conNo=$("#conNo").val();//合同号
				var pssconNo=$("#pssconNo").val();//外部合同号
				var conStatus=$("#conStatus").combobox("getValue"); //状态
				var deptAirportCode=$("#startCity").val(); //出发机场三字码
				var arrAirportCode=$("#arrCity").val(); //   到达机场三字码
 				console.log(conNo+","+pssconNo+','+conStatus+','+deptAirportCode+','+arrAirportCode);
				
				if(typeof(deptAirportCode) == 'undefined'){
					deptAirportCode = "";
				}
				if(typeof(arrAirportCode) == 'undefined'){
					arrAirportCode = "";
				}
				$('#ticketTable').datagrid('load',{"conNo":conNo,"pssconNo":pssconNo,"deptAirportCode":deptAirportCode,"arrAirportCode":arrAirportCode,"conStatus":conStatus,"temp":Math.random()});
			});
			//点击全部按钮时
			$("#all").click(function(){
				$('#ticketTable').datagrid('load',{});
			});
			//点击审核完成按钮
			$("#check_all").click(function(){
				$("#auditCount").html("(0)");
				$('#ticketTable').datagrid('load',{"msgStatus":msgStatus,"msgTime":msgTime,"temp":Math.random()});
			})
	}); 
	//查看日志
		function CheckLog(conNo){
			//alert(conNo);
			layer.open({
				type: 2,
				title: ['合同日志','background-color:#00B2EE; color:#fff;'],
				shadeClose: true,
				shade: 0.3,
				yes: function(index, layero) {
					layer.close(index);
				},
				btn2: function(index, layero) {
					//取消的回调
				},
				area: ['800px', '600px'],  
				content: ['${ctx}/np/contractLog?conNo='+conNo],  //iframe的url，no代表不显示滚动条
				success: function(layero, index){
					// layer.full(index);
				},
				end:function(){
					// localtion.reload();
				}
			});
		}
		//查看详情
		function LookDetail(conNo,conStatus,paymentOverTime){
			//alert(paymentOverTime);
			layer.open({
				type: 2,
				title: ['合同详情','background-color:#00B2EE; color:#fff;'],
				shadeClose: true,
				shade: 0.3,
				yes: function(index, layero) {
					layer.close(index);
				},
				btn2: function(index, layero) {
					//取消的回调
				},
				area: ['1200px', '1200px'],  
				content: ['${ctx}/np/contractDetailForPlatform?conNo='+conNo+'&conStatus='+conStatus+'&paymentOverTime='+paymentOverTime],  //iframe的url，no代表不显示滚动条
				success: function(layero, index){
					  layer.full(index);
				},
				end:function(){
					// localtion.reload();
				}
			});
		}
		//如果为空  对应的文本框为空
		function alsoempty(a,b){
			if(a.val() == "中文/拼音"){
				b.val("");
			};
		};
		</script>
	</head>
	<body>
	<div style="padding-left:10px;" >
		<div class="easyui-layout" data-options="fit:true,border:false" >
			<div id="toolbar">
				<div style="overflow:hidden;">
					<ul class="list">
						<li>
							合同号：
							<input type="text" id="conNo" class="textbox"  style="width:150px;height: 20px"/>
						</li>
						<li>
							外部合同号：
							<input type="text" id="pssconNo" class="textbox"  style="width:150px;height: 20px"/>
						</li>
						<li>出发城市：
						<input type="text" class="textbox" value="" size="15" id="homecity_name" name="homecity_name" style="width:150px;height: 20px" mod="address|notice" mod_address_source="hotel" mod_address_suggest="" mod_address_reference="startCity" mod_notice_tip="中文/拼音" />
						<input id="startCity" name="startCity" type="hidden" value="" />
						</li>
						<li>
						到达城市：
						<input type="text" class="textbox" value="" size="15" id="getcity_name" name="getcity_name" style="width:150px;height: 20px" mod="address|notice" mod_address_source="hotel"  mod_address_reference="arrCity" mod_notice_tip="中文/拼音" />
						<input id="arrCity" name="arrCity" type="hidden" value="" />
						</li>
						<li>
							 状态：
							<select class="easyui-combobox"  data-options="panelHeight:'auto'" id="conStatus">
								<option value="-1">全部</option>
								<option value="1">待审核</option>
								<option value="2">待支付</option>
								<option value="3">押金已收</option>
								<option value="4">合同中止</option>
								<option value="5">合同完成</option>
								<option value="6">合同退回</option>
								<option value="7">合同取消</option>
							</select>
						</li>
						<li><input type="button" value="查询" class="blue_btn" id="query"/></li>
					</ul>
				</div>
				<div>
					<input type="button" value="全部" class="blue_btn" id="all" />
					<a href="javascript:void(0)" class="blue_btn" id="check_all">审核完成<span id="auditCount"></span></a>
				</div>
			</div>
		</div>
	<div>
		<table id="ticketTable" class="easyui-datagrid" data-options="border:false"></table>
	</div>
</div>

	

<script type="text/javascript" src="${ctx }/jslib/airport/fixdiv.js"></script>
<script type="text/javascript" src="${ctx }/jslib/airport/address.js"></script>
<script type="text/javascript">
function closeAll() {  
	var allTabs = $("#tt").tabs('tabs');
	for(var i = 0, len = allTabs.length; i < len; i++) {
		//因为tabs删除之后会重新对其元素进行排序，所以在删除方法时候只需要进行删除1即可(因为我想保留第一个元素，如果不想保留就改成0即可)
		$("#tt").tabs('close', 0);
	} 
}
//定义参数可返回距 1970 年 1 月 1 日之间的毫秒数
function GetRTime(time,obj){
	//定义方法
	var startTime = new Date(time);
	//调用置指定时间的毫秒字段
	var EndTime=startTime.getTime();
    var NowTime = new Date();
    //定义参数可返回当天的日期和时间
    var nMS = EndTime - NowTime.getTime();
    //定义参数 EndTime减去NowTime参数获得返回距 1970 年 1 月 1 日之间的毫秒数
    var nD = Math.floor(nMS/(1000 * 60 * 60 * 24));
    //定义参数 获得天数
    var nH = Math.floor(nMS/(1000*60*60)) % 24;
    //定义参数 获得小时
    var nM = Math.floor(nMS/(1000*60)) % 60;
    //定义参数 获得分钟
    var nS = Math.floor(nMS/1000) % 60;
	if(nH < 10){nH = "0"+nH;}
	if(nM < 10){nM = "0"+nM;}
	if(nS < 10){nS = "0"+nS;}
    //定义参数 获得秒钟
    if (nMS > 0){
    //如果秒钟大于0
	   var str = nD+"天"+nH+"时"+nM+"分"+nS+"秒";
       //显示秒钟
	   $("#"+obj).html(str);
    }
}
 
</script>
    <jsp:include page="../footer.jsp"></jsp:include>
</body>
</html>